"""
递归，生成器实现八皇后
参考Python 基础教程
"""
def conflict(i, status):
    length = len(status)
    for lo in range(length):
        if i == status[lo] or (length - lo) == (abs(i - status[lo])):
            return True
    return False

def queens(num = 8, status = ()):
    for i in range(num):
        if not conflict(i, status):
            if len(status) == num - 1:
                yield (i,)
            else:
                for prev in queens(num, status + (i,)):
                    yield (i,) + prev




